package live.jialing.sip.base.domain;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.google.common.collect.Lists;
import live.jialing.core.beanvalidator.First;
import live.jialing.core.beanvalidator.Second;
import live.jialing.sip.base.dict.ClassCategoryEnum;
import live.jialing.structure.domain.Party;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.validator.constraints.NotBlank;

import javax.persistence.*;
import java.util.List;

/**
 * 班
 */
@Setter
@Getter
@ToString
@Entity
@DiscriminatorValue("class")
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id",scope = Squad.class)
public class Squad extends Party {

    @NotBlank(message = "入学年份不能为空", groups = {First.class, Second.class})
    private Integer grade;// 入学年份，年级

    private String alias;// 班的别名，如雷锋班

    @NotBlank(message = "班级编号不能为空", groups = {First.class, Second.class})
    private Integer num;// 编号、序号

    @NotBlank(message = "班级类别不能为空", groups = {First.class, Second.class})
    @Enumerated(EnumType.STRING)
    private ClassCategoryEnum category;// 班级类别

    // @NotBlank(message = "班级状态不能为空", groups = {First.class, Second.class})
    // @Enumerated(EnumType.STRING)
    // private ClassStatusEnum status;//状态

    // 学校
    @ManyToOne( fetch = FetchType.LAZY)
    @JoinColumn(name = "company_id",updatable = false)
    private School school;

    // 老师：包含班主任、任课老师
    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(name = "base_class_teacher_relation",
            inverseJoinColumns = {@JoinColumn(name = "teacher_id", referencedColumnName = "id")},
            joinColumns = {@JoinColumn(name = "class_id", referencedColumnName = "id")})
    private List<Teacher> teachers = Lists.newArrayList();

    // 学生
    @OneToMany(mappedBy = "squad", fetch = FetchType.LAZY)
    private List<Student> students = Lists.newArrayList();

}
